{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "76aef514",
   "metadata": {},
   "source": [
    "---\n",
    "* 时间：2022/10/18     \n",
    "* Python 课堂笔记\n",
    "------"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "2efe9ee9",
   "metadata": {},
   "source": [
    "## 本周知识点"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a780d401",
   "metadata": {},
   "source": [
    "> 1.while循环       \n",
    "> 2.购物车练习     \n",
    "> 3.元组_集合"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "eec5e79f",
   "metadata": {},
   "source": [
    "### While循环"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "803f4f67",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "你是风儿我是沙，哎呀我的妈呀停不下来了 ()\n"
     ]
    },
    {
     "ename": "TypeError",
     "evalue": "can only concatenate tuple (not \"int\") to tuple",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mTypeError\u001b[0m                                 Traceback (most recent call last)",
      "Input \u001b[1;32mIn [21]\u001b[0m, in \u001b[0;36m<cell line: 5>\u001b[1;34m()\u001b[0m\n\u001b[0;32m      4\u001b[0m \u001b[38;5;28;01mwhile\u001b[39;00m \u001b[38;5;28;01mTrue\u001b[39;00m:\n\u001b[0;32m      5\u001b[0m     \u001b[38;5;28mprint\u001b[39m(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m你是风儿我是沙，哎呀我的妈呀停不下来了\u001b[39m\u001b[38;5;124m\"\u001b[39m,count)\n\u001b[1;32m----> 6\u001b[0m     count \u001b[38;5;241m+\u001b[39m\u001b[38;5;241m=\u001b[39m\u001b[38;5;241m1\u001b[39m\n\u001b[0;32m      7\u001b[0m     \u001b[38;5;28;01mif\u001b[39;00m count \u001b[38;5;241m==\u001b[39m \u001b[38;5;241m100\u001b[39m:\n\u001b[0;32m      8\u001b[0m         \u001b[38;5;28;01mbreak\u001b[39;00m\n",
      "\u001b[1;31mTypeError\u001b[0m: can only concatenate tuple (not \"int\") to tuple"
     ]
    }
   ],
   "source": [
    "# while True 可以实现 for + range 的方法\n",
    "# while True 一般用于不确定的循环次数机或者无限次循环次数\n",
    "count = ()\n",
    "while True:\n",
    "    print(\"你是风儿我是沙，哎呀我的妈呀停不下来了\",count)\n",
    "    count +=1\n",
    "    if count == 100:\n",
    "        break"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "a56763c9",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "hide_card:88\n"
     ]
    }
   ],
   "source": [
    "# 猜数字小游戏： 0<n<100, 5次机会猜数字，每次猜完提示你猜的数字有点大/小\n",
    "\n",
    "hide_card = int(input(\"hide_card:\"))\n",
    "count = 0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "a3f3c4ce",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "hide_card:········\n",
      "game star\n",
      "guess_digit:50\n",
      "往小的想想\n",
      "guess_digit:40\n",
      "往小的想想\n",
      "guess_digit:30\n",
      "往小的想想\n",
      "guess_digit:20\n",
      "You got it!\n"
     ]
    }
   ],
   "source": [
    "import getpass\n",
    "hide_card = int(getpass.getpass(\"hide_card:\"))\n",
    "count= 0\n",
    "# print(hide_card)\n",
    "if hide_card < 100 and hide_card > 0:\n",
    "    print(\"game star\")\n",
    "    while True:\n",
    "        if count<5:\n",
    "            guess_digit = int(input(\"guess_digit:\"))# 玩游戏的人\n",
    "            if guess_digit == hide_card:\n",
    "                print(\"You got it!\")\n",
    "                break\n",
    "            elif guess_digit > hide_card:\n",
    "                print(\"往小的想想\")\n",
    "            else:\n",
    "                print(\"往大了猜\")\n",
    "            count = count+1\n",
    "        else:\n",
    "            print(\"5次你都猜不对耶！\")\n",
    "            print(\"正确答案是: %s\"%hide_card)\n",
    "            break\n",
    "else:\n",
    "    print(\"请输入0-99之间的数字，不许耍赖！\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "4f0843f0",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 1 运行程序后，让用户输入支付宝余额，然后打印商品列表给用户\n",
    "good_list = [\n",
    "    [\"蜜桃四季春\",6],\n",
    "    [\"柠檬四季春\",4],\n",
    "    [\"桃桃摇摇奶昔\",10],\n",
    "    [\"杨枝甘露\",12],\n",
    "]\n",
    "\n",
    "# 数据存放，列表的增加（append）\n",
    "shopping_list = []\n",
    "\n",
    "AliPay = int(input(\"请输入余额：\"))\n",
    "\n",
    "while True:\n",
    "    print(\"---------蜜雪冰城列表---------\")\n",
    "# 第一个[0]代表good_list中的蜜桃四季春，若为[1]则代表柠檬...，第二个[0]代表价格\n",
    "    for i in range(4):\n",
    "        print(i,good_list[i][0],good_list[i][1],\"元\")# 或print(good_list[i][0],str(good_list[i][1])+\"元\")\n",
    "    # 2 让用户输入商品编号进行购买\n",
    "    user_choice = int(input(\"请输入商品编号：\"))\n",
    "    # 3 用户选择商品后，检查用户的余额是否够，若够直接扣款，不够则提醒用户\n",
    "    # 3.1 用户输入商品序号\n",
    "    if user_choice.isdigit(): #判断用户是否输入序号\n",
    "        user_choice = int(user_choice)\n",
    "        if AliPay > good_list[user_choice][1]:\n",
    "        # 余额足够\n",
    "            AliPay = AliPay - good_list[user_choice][1] # 更新用户余额\n",
    "            shiooping_list.append(good_list[user_choice])\n",
    "            print(\"购买成功，请等待制作。您的余额还有：%s元\"%(AliPay))\n",
    "\n",
    "        else:\n",
    "            # 余额不够\n",
    "            print(\"您的余额不足\"+str(good_list[user_choice][1])+\"元，请更换支付方式\")\n",
    "        #3.2 用户输入其他\n",
    "    elif user_choice == \"q\":\n",
    "        print(\"感谢您的购买\")\n",
    "        print(\"您的购物车：\",shopping_list)\n",
    "        print(\"您的余额还有：\",AliPay)\n",
    "        break\n",
    "\n",
    "    else:\n",
    "        print(\"您输入的商品不存在\")\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "30accb0c",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "9ff624d7",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "d2c2fc39",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "9d10268c",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "781a7b9d",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "bb65e8b9",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
